using BCW;
using Holoville.HOTween;
using I2.Loc;
using UnityEngine;

public class GotchaRewardUI : MonoBehaviour
{
	public UIBasicSprite image;

	public new UILabel name;

	public UILabel count;

	public UISprite BG;

	public Color color1;

	public Color color2;

	public GotchaReward reward;

	public bool animateOnEnable;

	public void Set(GotchaReward reward, bool setAmount, bool color)
	{
		this.reward = reward;
		name.text = GetName(reward);
		if (setAmount)
		{
			if (reward.amount > 0)
			{
				count.gameObject.SetActive(true);
				count.text = reward.amount.ToString();
			}
			else
			{
				count.gameObject.SetActive(false);
			}
		}
		else
		{
			count.gameObject.SetActive(false);
		}
		SetTexture(reward);
		if (BG != null)
		{
			if (color)
			{
				BG.color = color1;
			}
			else
			{
				BG.color = color2;
			}
		}
	}

	private string GetName(GotchaReward reward)
	{
		if (reward.type == GotchaRewardType.Gold)
		{
			return ScriptLocalization.Get("Marathon/Coins");
		}
		if (reward.type == GotchaRewardType.Cash)
		{
			return ScriptLocalization.Get("Marathon/Cash");
		}
		Product product = MarketController.Instance.GetProduct(reward.id);
		if (product != null)
		{
			string fullLocMessage;
			if (!LocForVehicleUpgradeGotcha(product, out fullLocMessage))
			{
				return ScriptLocalization.Get("Market/" + product.id + "_title");
			}
			return fullLocMessage;
		}
		return null;
	}

	private bool LocForVehicleUpgradeGotcha(Product product, out string fullLocMessage)
	{
		if (product is ProductVehicleSkin)
		{
			fullLocMessage = ScriptLocalization.Get("Game_Common/CarM_gochaSkin") + " " + ScriptLocalization.Get("Market/" + (product as ProductVehicleSkin).targetId + "_title");
			return true;
		}
		if (product is ProductFreeUpgrade)
		{
			ProductFreeUpgrade productFreeUpgrade = product as ProductFreeUpgrade;
			switch (productFreeUpgrade.vehicleType)
			{
			case ProductVehicleType.Car:
				fullLocMessage = ScriptLocalization.Get("Game_Common/CarM_gotchaCarUpgrade");
				return true;
			case ProductVehicleType.Moto:
				fullLocMessage = ScriptLocalization.Get("Game_Common/CarM_gotchaBikeUpgrade");
				return true;
			case ProductVehicleType.Tank:
				fullLocMessage = ScriptLocalization.Get("Game_Common/CarM_gotchaTankUpgrade");
				return true;
			case ProductVehicleType.Titan:
				fullLocMessage = ScriptLocalization.Get("Game_Common/CarM_gotchaTitanUpgrade");
				return true;
			}
		}
		fullLocMessage = string.Empty;
		return false;
	}

	public Texture GetTexture(GotchaReward reward)
	{
		if (reward.type == GotchaRewardType.Cash)
		{
			return ReputationProductRewardWindow.instance.textureCash;
		}
		if (reward.type == GotchaRewardType.Gold)
		{
			return ReputationProductRewardWindow.instance.textureGold;
		}
		Product product = MarketController.Instance.GetProduct(reward.id);
		if (product is ProductVehicleSkin)
		{
			return MarketController.Instance.GetProductTextureExactForId("ASG_" + (product as ProductVehicleSkin).skinTextureName);
		}
		return MarketController.Instance.GetProductTexture(reward.id);
	}

	public void SetTexture(GotchaReward reward)
	{
		image = image.ReplaceForCurrentPlatform();
		switch (reward.type)
		{
		case GotchaRewardType.Product:
		{
			Product product = MarketController.Instance.GetProduct(reward.id);
			if (product is ProductVehicleSkin)
			{
				image.LoadTextureAndAlphaMask("AtlasShopGuns/", "ASG_" + (product as ProductVehicleSkin).skinTextureName);
			}
			else if (product is ProductVehicleUpgrade || product is ProductFreeUpgrade)
			{
				image.LoadTextureAndAlphaMask("AtlasShopGuns/Upgrades/", MarketController.Instance.GetProduct(reward.id).texture.Replace("Upgrades/", string.Empty));
			}
			else
			{
				image.LoadTextureAndAlphaMask("AtlasShopGuns/", MarketController.Instance.GetProduct(reward.id).texture);
			}
			break;
		}
		case GotchaRewardType.Cash:
			image.LoadTextureAndAlphaMask("NGUI_Textures/", "cash");
			break;
		case GotchaRewardType.Gold:
			image.LoadTextureAndAlphaMask("NGUI_Textures/", "gold");
			break;
		}
	}

	private void OnEnable()
	{
		if (animateOnEnable)
		{
			base.transform.localScale = Vector3.one * 0.5f;
			image.alpha = 0f;
			HOTween.To(image, 0.6f, new TweenParms().Prop("alpha", 1).Ease(EaseType.EaseInOutExpo));
			HOTween.To(base.transform, 1.5f, new TweenParms().Prop("localScale", Vector3.one).Ease(EaseType.EaseInOutElastic));
		}
	}
}
